package com.xiaocikuai.smallchunks.service.Transaction.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaocikuai.smallchunks.entity.Transaction.PromotionalUser;
import com.xiaocikuai.smallchunks.mapper.Transaction.PromotionalUserMapper;
import com.xiaocikuai.smallchunks.service.Transaction.IPromotionalUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaocikuai.smallchunks.utils.JWTservice.JwtService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author1
 * @since 2024-07-13
 */
@Service
public class PromotionalUserServiceImpl extends ServiceImpl<PromotionalUserMapper, PromotionalUser> implements IPromotionalUserService {


    @Resource
    PromotionalUserMapper promotionalUserMapper;

    @Resource
    private JwtService jwtService;

    public boolean adduser(String token, int promotion_id){
        PromotionalUser promotionalUser = new PromotionalUser();
        promotionalUser.setUid(jwtService.deconstruction(token).getUid());
        promotionalUser.setPromotionalId(promotion_id);
        promotionalUser.setIfdis(0);
        return promotionalUserMapper.insert(promotionalUser) == 1;
    }

    public boolean logicDelete(int uid, int promotionalId) {
        PromotionalUser promotionalUser = getOne(new LambdaQueryWrapper<PromotionalUser>()
                .eq(PromotionalUser::getUid, uid)
                .eq(PromotionalUser::getPromotionalId, promotionalId)
                .select());

        return lambdaUpdate()
                .eq(PromotionalUser::getPuId,promotionalUser.getPuId()) //设置更新的条件
                .set(PromotionalUser::getIfdis,1)        //设置更新的字段
                .update();
    }

}
